package com.cc.openeye.find.item

import com.cc.openeye.find.entity.find.Item
import com.cc.openeye.find.item.ItemViewType.AUTO_PLAY_VIDEO_AD
import com.cc.openeye.find.item.ItemViewType.BANNER
import com.cc.openeye.find.item.ItemViewType.BANNER3
import com.cc.openeye.find.item.ItemViewType.CARD_AUTHER
import com.cc.openeye.find.item.ItemViewType.COLUMN_CARD_LIST
import com.cc.openeye.find.item.ItemViewType.FOLLOW_CARD
import com.cc.openeye.find.item.ItemViewType.HORIZONTAL_SCROLL_CARD
import com.cc.openeye.find.item.ItemViewType.INFORMATION_CARD
import com.cc.openeye.find.item.ItemViewType.SPECIAL_SQUARE_CARD_COLLECTION
import com.cc.openeye.find.item.ItemViewType.TAG_BRIEFCARD
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_FOOTER2
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_FOOTER3
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_HEADER4
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_HEADER5
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_HEADER7
import com.cc.openeye.find.item.ItemViewType.TEXT_CARD_HEADER8
import com.cc.openeye.find.item.ItemViewType.TOPIC_BRIEFCARD
import com.cc.openeye.find.item.ItemViewType.UGC_SELECTED_CARD_COLLECTION
import com.cc.openeye.find.item.ItemViewType.UNKNOWN
import com.cc.openeye.find.item.ItemViewType.VIDEO_SMALL_CARD

object ItemTypeHelper {

    fun getItemViewType(item: Item): Int {
        return if (item.type == "textCard") getTextCardType(
            item.data?.type ?: ""
        ) else getItemViewType(item.type, item.data?.dataType ?: "")
    }

    private fun getItemViewType(type: String, dataType: String) = when (type) {

        "horizontalScrollCard" -> {
            when (dataType) {
                "HorizontalScrollCard" -> HORIZONTAL_SCROLL_CARD
                else -> UNKNOWN
            }
        }

        "specialSquareCardCollection" -> {
            when (dataType) {
                "ItemCollection" -> SPECIAL_SQUARE_CARD_COLLECTION
                else -> UNKNOWN
            }
        }

        "columnCardList" -> {
            when (dataType) {
                "ItemCollection" -> COLUMN_CARD_LIST
                else -> UNKNOWN
            }
        }

        "banner" -> {
            when (dataType) {
                "Banner" -> BANNER
                else -> UNKNOWN
            }
        }

        "banner3" -> {
            when (dataType) {
                "Banner" -> BANNER3
                else -> UNKNOWN
            }
        }

        "videoSmallCard" -> {
            when (dataType) {
                "VideoBeanForClient" -> VIDEO_SMALL_CARD
                else -> UNKNOWN
            }
        }

        "briefCard" -> {
            when (dataType) {
                "TagBriefCard" -> TAG_BRIEFCARD
                "TopicBriefCard" -> TOPIC_BRIEFCARD
                "BriefCard" -> CARD_AUTHER
                else -> UNKNOWN
            }
        }

        "followCard" -> {
            when (dataType) {
                "FollowCard" -> FOLLOW_CARD
                else -> UNKNOWN
            }
        }

        "informationCard" -> {
            when (dataType) {
                "InformationCard" -> INFORMATION_CARD
                else -> UNKNOWN
            }
        }

        "ugcSelectedCardCollection" -> {
            when (dataType) {
                "ItemCollection" -> UGC_SELECTED_CARD_COLLECTION
                else -> UNKNOWN
            }
        }

        "autoPlayVideoAd" -> {
            when (dataType) {
                "AutoPlayVideoAdDetail" -> AUTO_PLAY_VIDEO_AD
                else -> UNKNOWN
            }
        }

        else -> UNKNOWN
    }

    private fun getTextCardType(type: String) = when (type) {
        "header4" -> TEXT_CARD_HEADER4
        "header5" -> TEXT_CARD_HEADER5
        "header7" -> TEXT_CARD_HEADER7
        "header8" -> TEXT_CARD_HEADER8
        "footer2" -> TEXT_CARD_FOOTER2
        "footer3" -> TEXT_CARD_FOOTER3
        else -> UNKNOWN
    }
}